package com.sdkx.app.model;

import android.text.TextUtils;
import android.widget.TextView;

import com.sdkx.app.model.ViewObject;
import com.sdkx.app.util.CharacterParser;


/**
 * 航图上的点基础类，自定义航点，标记，机场等都需要继承此类
 */
public class AirpointBase extends ViewObject {
    private int id;//自增长主键
    private String latitude;//纬度，存储格式为 度+分+秒，秒保留两位小数，分占两位数字位，秒占5位。例如1234523.01代表123度45分23.01秒
    private String longitude;//经度
    private String east_or_west;//东西经,存储值为“E”或“W”
    private String south_or_north;//南北纬,存储值为“N”或“S”

    public int getId() {
        return id;
    }

    public String getLatitude() {
        return south_or_north+latitude;
    }

    public void setLatitude(String latitude) {
        if(latitude.startsWith("N")|| latitude.startsWith("S")){
            setSouth_or_north(latitude.substring(0,1));
        }
        this.latitude = latitude.substring(1,latitude.length());
    }

    public String getLongitude() {
        return east_or_west+longitude;
    }

    public void setLongitude(String longitude) {
        if(longitude.startsWith("E")||longitude.startsWith("W")){
            setEast_or_west(longitude.substring(0,1));
        }
        this.longitude = longitude.substring(1,longitude.length());
    }

    public String getEast_or_west() {
        return east_or_west;
    }

    public void setEast_or_west(String east_or_west) {
        this.east_or_west = east_or_west;
    }

    public String getSouth_or_north() {
        return south_or_north;
    }

    public void setSouth_or_north(String south_or_north) {
        this.south_or_north = south_or_north;
    }

    public Double getDoubleLongitude() {
        double tempValue = Double.parseDouble(longitude);
        tempValue = ((int) (tempValue / 10000)) +  (((int)(tempValue % 10000) / 100)/ 60f) + (tempValue * 100 % 10000) / 360000;
        if(TextUtils.isEmpty(east_or_west))
            east_or_west = "E";
        if (east_or_west.toUpperCase().equals("W")) {
            return -tempValue;
        } else {
            return tempValue;
        }
    }

    public Double getDoubleLatitude() {
        double tempValue = Double.parseDouble(latitude);
//        tempValue = tempValue/10000 + ((tempValue%10000)/100)/60 + (tempValue%100)/3600;
        int degree =  (int)(tempValue / 10000);
        double  miao =  (((int)((tempValue % 10000) / 100)) / 60f);
        double fen =  (tempValue * 100 % 10000) / 360000f;

        double tempdegree  = degree+miao+fen;
        if(TextUtils.isEmpty(south_or_north))
            south_or_north = "N";
        if (south_or_north.toUpperCase().equals("S")) {
            return -tempdegree;
        } else {
            return tempdegree;
        }
    }

}
